package com.situ.water_system.controller;


import com.situ.water_system.mapper.SyEmpMapper;
import com.situ.water_system.pojo.SyDept;
import com.situ.water_system.pojo.SyEmp;
import com.situ.water_system.service.SyDeptService;
import com.situ.water_system.service.SyEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@RestController
@RequestMapping("/Syemp")
public class SyEmpController {
    @Autowired
    private SyEmpService service;
    @Autowired
    private SyEmpMapper dao;
    @RequestMapping("/queryall")
    public List<SyEmp> queryall() {
        return service.selectList();
    }

    @RequestMapping("/queryByid/{id}")
    public SyEmp queryByid(@PathVariable(name = "id") Integer id) {
        return service.selectByid(id);
    }

    @RequestMapping("/del/{id}")
    public int del(@PathVariable(name = "id") Integer id) {
        return service.del(id);
    }

    @RequestMapping("/add")
    public int insert(SyEmp syArea) {
        return service.add(syArea);
    }

    @RequestMapping("/update")
    public int update(SyEmp syArea) {
        return service.update(syArea);
    }
    @RequestMapping("/queryByids")
    public List<SyEmp> queryByids(Integer[] empids){
        List list = new ArrayList();
        for (Integer empid : empids) {
            list.add(service.selectByid(empid));
        }
        return list;
    }
    @RequestMapping("/login")
    public int login(String username, String password, HttpSession session){
        SyEmp queryidmohu = service.queryidmohu(username, password);
        if(queryidmohu!=null){
              session.setAttribute("user", queryidmohu);
              return 1;
        }
        return  0;
    }
    @RequestMapping("/chax")
    public SyEmp chax(HttpSession session){
        SyEmp user =(SyEmp)session.getAttribute("user");
        return user;
    }
    @RequestMapping("/close")
    public int login(HttpSession session){
            session.invalidate();
            return 1;
    }
    @RequestMapping("/workspace")
    public List<Map> workspace(){
        return dao.workspace();
    }
}

